package com.ximi.ximimall.authcenter.domain;


import com.ximi.ximimall.model.LitemallUser;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Arrays;
import java.util.Collection;

/**
 * @author 西米的风
 * @description TODO
 * @date 2022-10-13 23:07
 */
public class LitemallUserDetails implements UserDetails {
    private LitemallUser litemallUser;

    public LitemallUserDetails(LitemallUser litemallUser) {
        this.litemallUser = litemallUser;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        //返回当前用户的权限
        return Arrays.asList(new SimpleGrantedAuthority("TEST"));
    }

    @Override
    public String getPassword() {
        return litemallUser.getPassword();
    }

    @Override
    public String getUsername() {
        return litemallUser.getUsername();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return litemallUser.getStatus()==0;
    }

    public LitemallUser getLitemallUser() {
        return litemallUser;
    }
}
